﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Vehicle_Maintenance
{
    public partial class Vehicle_Maintenance : Form
    {
        private Person activeUser = new Person();
        private Vehicle activeCar = new Vehicle();

        public Vehicle_Maintenance()
        {
            InitializeComponent();
        }

        private void Vehicle_Maintenance_Load(object sender, EventArgs e)
        {
            bool succ = false;
            Change_User_or_Car dlg = new Change_User_or_Car();
            if ( dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK )
            {
                while ( !succ )
                {
                    try
                    {
                        activeUser.LoadByID( ( (ComboBox)dlg.Controls.Find( "cb_User", true )[ 0 ] ).SelectedValue.ToString() );
                        activeCar.LoadByVIN( ( (ComboBox)dlg.Controls.Find( "cb_Car", true )[ 0 ] ).SelectedValue.ToString() );
                        succ = true;
                    }
                    catch
                    {
                        MessageBox.Show( "Failed to load user and car information." );
                    }
                }
            }
            else
            {
                Close();
            }
            l_Name.Text = activeUser.LastName + ", " + activeUser.FirstName;
        }

        #region Change to different entities
        private void personToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Change_User_or_Car dlg = new Change_User_or_Car();
            dlg.ShowDialog();
        }

        private void carToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Change_User_or_Car dlg = new Change_User_or_Car();
            dlg.ShowDialog();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        } 
        #endregion

        #region Add new entities
        private void personToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            User dlg = new User();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Add new user to the database
            }
        }

        private void carToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Car dlg = new Car();
            if ( dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK )
            {
                // Add new car to the database
            }
        }

        private void gasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Gas_Log dlg = new Gas_Log();
            dlg.ShowDialog();
        }

        private void serviceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Service_Log dlg = new Service_Log();
            dlg.ShowDialog();
        } 
        #endregion

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
